package com.qf.springboot.mail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * projectName: springboot
 *
 * @author dongshihao
 * Date:2021/9/12   22:32
 * description:
 */
@Component
public class MailTest {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    public void mailSend() throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();

        MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,true);
        messageHelper.addTo("3090930041@qq.com");
        messageHelper.setSubject("测试springboot");
        messageHelper.setText("test/html","<h1 style='color:red;'>嘿嘿嘿！</h1>");
        messageHelper.setFrom(from);

        javaMailSender.send(mimeMessage);
    }


}
